package com.yu.crm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yu.crm.domain.pojo.CrmManageAttachment;
import com.yu.crm.domain.pojo.PubAttachment;
import com.yu.crm.mapper.CrmManageAttachmentMapper;
import com.yxzz.common.helper.DataHelpers;
import com.yxzz.common.helper.DateHelpers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ct
 * @since 2020-06-22
 */
@Service
public class CrmManageAttachmentService extends ServiceImpl<CrmManageAttachmentMapper, CrmManageAttachment> {

    @Autowired
    PubAttachmentService pubAttachmentService;

    public void saveAttachment(Long id, String[] split) {
        if (DataHelpers.isNotEmpty(split) && split.length >0 ) {
            List<CrmManageAttachment> list = new ArrayList<>();
            for (String attId : split) {
                CrmManageAttachment c = new CrmManageAttachment();
                c.setAreaManageId(id);
                c.setAttachmentId(Long.parseLong(attId));
                c.setGmtCreate(DateHelpers.now());
                list.add(c);
            }
            this.saveBatch(list);
        }
    }

    public void delById(Long id) {
        QueryWrapper<CrmManageAttachment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("area_manage_id",id);
        baseMapper.delete(queryWrapper);
    }

    public List<PubAttachment> listById(Long id) {
        return baseMapper.listById(id);
    }
}
